package com.ssy.lingxi.member.merchant.serviceimpl.web;

import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.model.constant.MemberRegisterSourceEnum;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.EmailVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.MemberDetailVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.PhoneVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.SmsPhoneVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.MemberConfigGroupVO;
import com.ssy.lingxi.member.merchant.model.vo.login.request.MemberRegisterVO;
import com.ssy.lingxi.member.merchant.model.vo.login.request.ResetPasswordByEmailCodeVO;
import com.ssy.lingxi.member.merchant.model.vo.login.request.ResetPasswordBySmsCodeVO;
import com.ssy.lingxi.member.merchant.model.vo.login.response.MemberRegisterResultVO;
import com.ssy.lingxi.member.merchant.model.vo.login.response.MemberRegisterTypeMenuVO;
import com.ssy.lingxi.member.merchant.service.base.IBaseMemberCacheService;
import com.ssy.lingxi.member.merchant.service.base.IBaseRegisterService;
import com.ssy.lingxi.member.merchant.service.web.IMemberRegisterService;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户注册接口实现类
 * @author 万宁
 * @version 2.0.0
 * @date 2020-06-03
 */
@Service
public class MemberRegisterServiceImpl implements IMemberRegisterService {

    @Resource
    private IBaseRegisterService baseRegisterService;

    @Resource
    private IBaseMemberCacheService memberCacheService;

    /**
     * 检查手机号码是否被注册使用
     * @param headers Http头部信息
     * @param phoneVO 手机号码
     * @return 检查结果
     */
    @Override
    public Wrapper<Void> checkPhoneRegistered(HttpHeaders headers, PhoneVO phoneVO) {
        memberCacheService.checkWebRequestHeader(headers);
        return baseRegisterService.checkPhoneRegistered(phoneVO);
    }

    /**
     * 检查邮箱是否被注册使用
     * @param headers Http头部信息
     * @param emailVO 邮箱
     * @return 检查结果
     */
    @Override
    public Wrapper<Void> checkEmailRegistered(HttpHeaders headers, EmailVO emailVO) {
        memberCacheService.checkWebRequestHeader(headers);
        return baseRegisterService.checkEmailRegistered(emailVO);
    }

    /**
     * 发送注册时短信验证码
     * @param headers Http头部信息
     * @param phoneVO 接口参数
     * @return 发送结果
     */
    @Override
    public Wrapper<Void> sendRegisterSmsCode(HttpHeaders headers, SmsPhoneVO phoneVO) {
        memberCacheService.checkWebRequestHeader(headers);
        return baseRegisterService.sendRegisterSmsCode(phoneVO);
    }

    /**
     * 发送手机号找回密码时的短信验证码
     * @param headers Http头部信息
     * @param phoneVO 手机号码
     * @return 发送结果
     */
    @Override
    public Wrapper<Void> sendResetPasswordSmsCode(HttpHeaders headers, SmsPhoneVO phoneVO) {
        memberCacheService.checkWebRequestHeader(headers);
        return baseRegisterService.sendResetPasswordSmsCode(phoneVO);
    }

    /**
     * 根据短信验证码重设密码
     * @param headers Http头部信息
     * @param codeVO 接口参数
     * @return 操作结果
     */
    @Override
    public Wrapper<Void> resetPasswordBySmsCode(HttpHeaders headers, ResetPasswordBySmsCodeVO codeVO) {
        memberCacheService.checkWebRequestHeader(headers);
        return baseRegisterService.resetPasswordBySmsCode(codeVO);
    }

    /**
     * 发送邮箱找回密码时的邮件
     * @param headers Http头部信息
     * @param emailVO 邮箱地址
     * @return 发送结果
     */
    @Override
    public Wrapper<Void> sendResetPasswordEmail(HttpHeaders headers, EmailVO emailVO) {
        memberCacheService.checkWebRequestHeader(headers);
        return baseRegisterService.sendResetPasswordEmail(emailVO, false);
    }

    /**
     * 根据邮箱验证码重设密码
     * @param headers Http头部信息
     * @param codeVO 接口参数
     * @return 操作结果
     */
    @Override
    public Wrapper<Void> resetPasswordByEmailCode(HttpHeaders headers, ResetPasswordByEmailCodeVO codeVO) {
        memberCacheService.checkWebRequestHeader(headers);
        return baseRegisterService.resetPasswordByEmailCode(codeVO);
    }

    /**
     * 获取会员注册页面-会员类型、商业类型页面内容（第二页）
     * @param headers Http头部信息
     * @return 操作结果
     */
    @Override
    public Wrapper<List<MemberRegisterTypeMenuVO>> getRegisterTypePageContent(HttpHeaders headers) {
        memberCacheService.checkWebRequestHeader(headers);
        return baseRegisterService.getRegisterTypePageContent();
    }

    /**
     * 获取会员注册页面-详细信息页面内容（第三页）
     * @param headers Http头部信息
     * @param detailVO 接口参数
     * @return 注册第三页的内容
     */
    @Override
    public Wrapper<List<MemberConfigGroupVO>> getRegisterDetailPageContent(HttpHeaders headers, MemberDetailVO detailVO) {
        memberCacheService.checkWebRequestHeader(headers);
        return baseRegisterService.getRegisterDetailPageContent(detailVO);
    }

    /**
     * Web站点页面注册
     * @param headers Http头部信息
     * @param registerVO 接口参数
     * @return 注册结果
     */
    @Override
    public Wrapper<MemberRegisterResultVO> registerPlatformMember(HttpHeaders headers, MemberRegisterVO registerVO) {
        memberCacheService.checkWebRequestHeader(headers);
        return baseRegisterService.registerPlatformMember(MemberRegisterSourceEnum.FROM_ENTERPRISE_WEB_SHOP,registerVO.getSmsCode(),registerVO.getCountryCode(),registerVO.getPhone(),registerVO.getPassword(),registerVO.getEmail(),registerVO.getTypeId(),registerVO.getBusinessTypeId(),registerVO.getDetail());
    }
}